#![feature(downcast_unchecked)]
#![feature(future_join)]

use std::future::join;
use std::sync::Arc;

use futures_util::future::join_all;

use common::LResult;
use flight_sql::start_flight_sql_service;
use http::start_http_service;

use crate::db::LiteDB;

mod db;

pub async fn start_server() -> LResult<()> {
    let db = Arc::new(LiteDB::create());
    let f0 = start_flight_sql_service(db.clone());
    let f1 = start_http_service(db);
    let _ = join!(f0, f1).await;
    Ok(())
}

#[cfg(test)]
mod test {
    use std::env::current_dir;

    use common::LResult;

    use crate::start_server;

    #[tokio::test]
    async fn test() -> LResult<()> {
        let pwd = current_dir().unwrap().into_os_string();
        println!("pwd: {}", pwd.to_str().unwrap());
        log4rs::init_file("../conf/log4rs.yaml", Default::default()).unwrap();
        start_server().await
    }
}